package com.site.wisdom_construction.controller.iotModule;

import com.alibaba.fastjson.JSONObject;
import com.site.wisdom_construction.responseEntity.TwoDataResult;
import com.site.wisdom_construction.util.HttpRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @Author daiyifei
 * @Date 2022/3/7
 * @Description
 */
@Api(tags = "护栏监测信息接口")
@RestController
@RequestMapping("GuardBar")
@CrossOrigin
public class GuardBarController {

    @ApiOperation(value = "护栏", notes = "")
    @PostMapping("/findHuLan")
    public TwoDataResult findHuLan() throws InterruptedException {
        TwoDataResult twoDataResult = new TwoDataResult();
        JSONObject jsonObject = new JSONObject();
        JSONObject jsonObjectOne = new JSONObject();
        JSONObject jsonObjectTwo = new JSONObject();
        JSONObject jsonObjectThree = new JSONObject();
        HttpRequest httpRequest =new HttpRequest();
        String path = "https://api.dtuip.com/qy/user/login.html";
        String path1 = "https://api.dtuip.com/qy/alarms/queryAlarms.html";
        String path2 = "https://api.dtuip.com/qy/alarms/queryAlarmsHistory.html";
        jsonObjectOne.put("userName","18258811713");
        jsonObjectOne.put("password","12345678");
        jsonObject = httpRequest.JsonData(path,jsonObjectOne);
        JSONObject object = new JSONObject();
        object.put("page",1);
        object.put("userApiKey",jsonObject.get("userApikey"));
        object.put("flagCode",jsonObject.get("flagCode"));
        TimeUnit.SECONDS.sleep(1);
        jsonObjectTwo = httpRequest.JsonData(path1,object);
        System.out.println("jsonObjectTwo:"+jsonObjectTwo);
        twoDataResult.setDataOne(jsonObjectTwo);
        TimeUnit.SECONDS.sleep(1);
        jsonObjectThree = httpRequest.JsonData(path2,object);
        System.out.println("jsonObjectThree:"+jsonObjectThree);
        twoDataResult.setDataTwo(jsonObjectThree);
        return twoDataResult;
    }
}
